package circuits;

import java.util.HashMap;
import java.util.HashSet;

public abstract class Component {

	protected HashMap<String,Input> connectedInputs;
	private HashSet<String> inputNames;
	protected HashMap<String,Boolean> inputValues;
	protected Output output;
	
	public Component(){
		this.connectedInputs = new HashMap<String, Input>();
		this.inputValues = new HashMap<String, Boolean>();
		this.inputNames = new HashSet<String>();
		this.output = null;
	}
	
	public boolean addInputName(String inputName){
		return this.inputNames.add(inputName);
	}
	
	public boolean removeInputName(String inputName){
		return this.inputNames.remove(inputName);
	}
	
	private boolean isInput(String inputName){
		return this.inputNames.contains(inputName);
	}
	
	public boolean connectInput(String inputName,Input input){
		if ((this.isInput(inputName)) && (input != null)){
			this.connectedInputs.put(inputName, input);
			return true;
		}
		return false;
	}
	
	public void connectOutput(Output output){
		this.output = output;
	}
	
	public abstract void readInputValues();
	
	public abstract void generateOutput();
}
